﻿@model Model.DictionaryInfo
@{
    ViewBag.Title = "编辑字典配置";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<style type="text/css">
    textarea
    {
        width: 400px;
        border: 1px solid #ccc;
        padding: 2px;
    }
    .pwdw
    {
        width: 148px;
    }
    .hide
    {
        display: none;
    }
</style>
<script type="text/javascript">
    $(function () {
        if ($.getUrlParam("type") == "2") {
            $(".item").hide();
        } else {
            $.post('/PEPara/GetParentList', function (result) {
                for (var i = 0; i < result.rows.length; i++) {
                    var sed = "";
                    if ('@Model.ParentID' == result.rows[i].Guid)
                        sed = " selected"
                    $("#selParentID").append("<option value='" + result.rows[i].Guid + "' " + sed + ">" + result.rows[i].Name + "</option>");
                }
            });
        }
    })
    function save() {
        if ($.trim($("#txtName").val()) == "") {
            alert("名称不能为空！");
            return;
        }
        if ($.trim($("#txtValue").val()) == "" && $.getUrlParam("type") == "1") {
            alert("值不能为空！");
            return;
        }
        if ($.trim($("#txtDescription").val()) == "") {
            alert("描述不能为空！");
            return;
        }
        if ($.getUrlParam("type") == "2") {
            $("#selParentID").val("");
            $("#txtValue").val("0"); 
        }
        $.post('/PEPara/SaveData', { query: jv.GetDivJson($(".searchArea"), 3) }, function (result) {
            switch (result) {
                case "1":
                    alert("保存成功！");
                    BackToList();
                    break;
                case "2":
                    alert("配置值在该组配置中已存在!");
                    return false;
                    break;
                case "3":
                    alert("配置名称已存在!");
                    return false;
                    break;
                default:
                    alert("保存失败");
                    return false;
                    break;
            }
        });
    }
    function BackToList() {
        if ($.getUrlParam("id") && $.getUrlParam("type") == "1") {
            window.location.href = "/PEPara/DictList?ParentID=" + $("#selParentID").val() + "&name=" + $("#selParentID").find("option:selected").text(); 
        }
        else
            window.location.href = "/PEPara/DictionaryShow";
    }
  
</script>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                编辑字典配置
            </td>
            <td align="right">
                <input id="Save" type="button" class="button" value=" 保存 " onclick="save()" />
                <input type="button" class="button" value=" 返回 " onclick="back();" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td style="width: 80px; text-align: right;">
                <span class="red">*</span>名称：
            </td>
            <td>
                <input type="text" id="txtName" name="Name" maxlength="25" value="@Model.Name" style="width: 220px" />
                <input type="hidden" name="Guid" id="hddGuid" value="@Model.Guid" />
            </td>
        </tr>
        <tr class="item">
            <td style="text-align: right;">
                <span class="red">*</span>值：
            </td>
            <td>
                <input type="text" id="txtValue" name="Value" value="@Model.Value" @(Model.Guid == null ? "" : "disabled='disabled'")  style="width: 220px"  />
            </td>
        </tr>
        <tr class="item">
            <td style="text-align: right;">
                分类：
            </td>
            <td>
                <select id="selParentID">
                </select>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                <span class="red">*</span>描述：
            </td>
            <td>
                <textarea id="txtDescription" name="Description" style="width: 420px; height: 100px">@Model.Description</textarea>
            </td>
        </tr>
        <tr class="item">
            <td style="text-align: right;">
                排序号：
            </td>
            <td>
                <input type="text" id="txtOrderNo" name="OrderNo" value="@Model.OrderNo" class="easyui-numberspinner" data-options="required:true" />
            </td>
        </tr>
    </table>
</div>
